package model;

import java.util.TreeMap;

public class Cart {
	private long idCart;
	private TreeMap<Item, Integer> listItem;
	public Cart(){
		idCart = System.currentTimeMillis();
		listItem = new TreeMap<Item, Integer>();
	}
	public Cart(long idCart, TreeMap<Item, Integer> listItem) {
		this.idCart = idCart;
		this.listItem = listItem;
	}
	
	public void insertItem(Item item, int quantity) {
		boolean check = listItem.containsKey(item);
		Integer countAdd = 0;
		System.out.println(quantity+"   quantity");
		if (check) {
			Integer old_quantity = listItem.get(item);
			quantity = quantity + old_quantity;
			countAdd = listItem.put(item, quantity);
		} else {
			countAdd = listItem.put(item, quantity);
		}
	}
	public void updateItem(Item item, int quantity) {
		boolean check = listItem.containsKey(item);
		if (check == true) {
			if (quantity <= 0) {
				listItem.remove(item);
			} else {
				listItem.remove(item);
				listItem.put(item, quantity);
			}
		}
	}
	public long getIdCart() {
		return idCart;
	}
	public void setIdCart(long idCart) {
		this.idCart = idCart;
	}
	public TreeMap<Item, Integer> getListItem() {
		return listItem;
	}
	public void setListItem(TreeMap<Item, Integer> listItem) {
		this.listItem = listItem;
	}

}
